package commands;

import com.amazonaws.services.s3.AmazonS3;
import com.amazonaws.services.s3.model.CopyObjectRequest;
import com.amazonaws.services.s3.model.CopyObjectResult;
import jesss.commands.CommandResult;
import jesss.commands.JesssCommand;
import jesss.commands.JesssCommandFactoryImpl;
import jesss.commands.ResultStatus;
import jesss.options.JesssOptions;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;

import java.util.Date;

import static org.mockito.Matchers.any;
import static org.mockito.Mockito.*;

/**
 * User: Lee
 * Date: 9/8/13
 * Time: 7:40 PM
 */
public class MoveObjectCommandTests extends CommandTestsBase {
    private AmazonS3 mockS3 = mock(AmazonS3.class);
    private JesssOptions mockJesssOptions = mock(JesssOptions.class);

    @Before
    public void setUp() throws Exception {

        CopyObjectResult copyObjectResult = new CopyObjectResult();
        copyObjectResult.setLastModifiedDate(new Date());
        copyObjectResult.setETag("targetkey");

        stub(mockJesssOptions.getAmazonS3()).toReturn(mockS3);
        stub(mockJesssOptions.getCommandName()).toReturn("mo");
        stub(mockJesssOptions.getShouldDisplayVerbose()).toReturn(true);
        stub(mockS3.copyObject(any(CopyObjectRequest.class))).toReturn(copyObjectResult);
    }

    @Test
    public void CanMoveObject() throws Exception {

        String[] args = {"-sbn", "sourcebucket", "-sk", "sourcekey", "-tbn", "targetbucket", "-tk", "targetkey"};
        JesssCommand moveObjectCommand = JesssCommandFactoryImpl.getInstance().createCommand(mockS3, mockJesssOptions.getCommandName(), mockJesssOptions.getShouldDisplayVerbose(), args);

        CommandResult commandResult = moveObjectCommand.executeCommand();

        Assert.assertEquals("Expected copy to be successful.", ResultStatus.Success, commandResult.getResultStatus());
    }

}
